package com.refactor.demo;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	private String name;

	public Customer() {
	}

	public Customer(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public String statement(Vector<Rental> rentals) {
		double totalAmount = 0;
		int frequentRenterPoints = 0;
		Enumeration<Rental> rental = rentals.elements();
		StringBuffer result = new StringBuffer("Rental Record for ").append(getName()).append("\n");
		while (rental.hasMoreElements()) {
			double thisAmount = 0D;
			Rental each = (Rental) rental.nextElement();
			thisAmount = each.getCharge();
			//show figures for this rental
			result.append("\t").append(each.getMovie().getTitle());
			result.append("\t" ).append(thisAmount).append("\n");
			//数量汇总
			totalAmount += thisAmount;
			//积分累计
			frequentRenterPoints += each.getIntegralPoints();
		}
		//add footer lines
		result.append("Amount owed is ").append( totalAmount).append("\n");
		result.append("You earned").append(frequentRenterPoints).append(" frequent renter points") ;
		return result.toString();
	}
}
